﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebVideo.Areas.Admin.Models;

namespace WebVideo.Controllers
{
    public class NSiteInfoController : Controller
    {
        //
        // GET: /NSiteInfo/

        public ActionResult Index()
        {
            return View();
        }
        //id = 1
        #region "GioiThieu"
        public ActionResult GioiThieu()
        {
            dbVideoDataContext db = new dbVideoDataContext();
            EntitySiteInfo cp = db.EntitySiteInfos.Where(g => g.Id == 1).First(); 
            return View(cp);
        }
        #endregion

        #region "GetCompany"
        public ActionResult GetCompany()
        {
            dbVideoDataContext db = new dbVideoDataContext();
            EntityCompany cp = db.EntityCompanies.First();
            return PartialView(cp);
        }
        #endregion

        //id = 2
        #region "LienHe"
        public ActionResult LienHe()
        {
            dbVideoDataContext db = new dbVideoDataContext();
            EntityCompany cp = db.EntityCompanies.First();
            return View(cp);
        }
        #endregion

        //id = 3
        #region "Điều khoản dịch vụ"
        public ActionResult DieuKhoanDichVu()
        {
            dbVideoDataContext db = new dbVideoDataContext();
            EntitySiteInfo cp = db.EntitySiteInfos.Where(g => g.Id == 3).First();
            return View(cp);
        }
        #endregion
        //id = 4
        #region "Chính sách bảo mật"
        public ActionResult ChinhSachBaoMat()
        {
            dbVideoDataContext db = new dbVideoDataContext();
            EntitySiteInfo cp = db.EntitySiteInfos.Where(g => g.Id == 4).First();
            return View(cp);
        }
        #endregion

        #region "Câu hỏi thường gặp"
        public ActionResult FAQ()
        {
            dbVideoDataContext db = new dbVideoDataContext();
            
            return View(FAQModel.Index());
        }
        #endregion
        #region "Quy Định"
        public ActionResult QuyDinh()
        {
            dbVideoDataContext db = new dbVideoDataContext();
            EntitySiteInfo cp = db.EntitySiteInfos.Where(g => g.Id == 6).First();
            return View(cp);
        }
        #endregion

        //id = 5
        #region "SuDungWebSite"
        public ActionResult SuDungWebSite()
        {
            dbVideoDataContext db = new dbVideoDataContext();
            EntitySiteInfo cp = db.EntitySiteInfos.Where(g => g.Id == 5).First();
            return View(cp);
        }
        #endregion

        #region "ADMIN Support"
        public ActionResult AdminSupport(string UserName)
        {
            dbVideoDataContext db = new dbVideoDataContext();
          //  IEnumerable<EntitySupportAdmin> cp = db.EntitySupportAdmins.Where(g => g.UserName == UserName || g.IdRoot == UserName).OrderBy(g => g.Date).ToList();
            var query = from p in db.EntitySupportAdmins
                        where p.UserName == UserName || p.IdRoot == UserName
                        select p;
            return PartialView(query.ToList().Take(14));
        }
        #endregion

        #region "InsertAdminSupport"
        public string InsertAdminSupport(string UserName, string Contents)
        {
            try
            {

                dbVideoDataContext db = new dbVideoDataContext();
                EntitySupportAdmin sp = new EntitySupportAdmin();
                sp.Contents = Contents;
                sp.Date = DateTime.Now;
                sp.UserName = UserName;
                //sp.IdRoot = Admin;
                db.EntitySupportAdmins.InsertOnSubmit(sp);
                db.SubmitChanges();
                //return RedirectToAction("LienHe", "NSiteInfo");
                return "ok";
            }
            catch
            {
                return "error";
            }
        }
        #endregion
       

    }
}
